#define _USE_POSIX 1
#include <ftw.h>
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>

#define BUFF_SIZE	100


struct fileExp
{
	char **fileNames;// Array of filenames.
	int size;	 // number of Items in the array
	int capacity;	 // Size of the array
};

struct fileExp ftwMatch;

/* Gets the input from STDIN and returns
   a character pointer to heap allocated
   memory.
*/
char* getinputstring();

/* Removes whitespace from beginnig and end of command
   and anything after a word beginning with a'#' character 
   including the '#' character
*/
void sanatize(char* cmd);

/* Returns a pointer to an array of strings, each of which
   corresponds to a directory from the $PATH environment
   variable.
*/
char** getPathEnv();

/* Returns the number of occurances of c in str */
int countchar(const char *str, const char* c);

/* Returns an array of strings seperated by sep */
char** getTokens(const char *str, const char* sep);

/* Expands any '*' and '?' to alphabetic list of filenames */
char** expandFileName(const char *path, const char* match);

void treeTraversal(const char *path, const char *patern);

/* Returns changes all '*' to '.*' and all '?' to '.?' */
char* formRegex(const char *str);

/* Checks if it matches the regex */
int ftwCmp(const char* fpath, const struct stat* sb, int typeflag);

/* Checks all of the files under envPath directories and returns
   the first valid one */
char* getExecPath(char **envPath, const char* name);


/* Returns 1 if str is a valid directory */
int isDir(const char* str);

/* Returns 1 if there is any unescaped regular expression
   characters in str.  '*', '?' */
int unescapedRegex(const char* str);

/* Parses a string and returns all the arguments.
   strings enclosed in " " or ' ' are kept as a
   single argument */
char** parseArgs(const char *str);

/* Converts '\ ' to ' ' and '\\' to '\'  */
void removeUnescaped(char** str);

void freeArr(char** arr);

void sortFileNames(char** names);

